package com.grep.web;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.grep.base.db.DBUtils;
import com.grep.extra.dao.BaseDao;

import com.grep.extra.dao.impl.BaseDaoImpl;
import com.grep.extra.dao.impl.TaskDAOSQL;

import com.grep.extra.dao.impl.WebSiteDAOSQL;
import com.grep.extra.factory.data.impl.SiteUrl;
import com.grep.extra.factory.data.impl.TaskUrl;
import com.grep.web.dto.TaskUrlDto;

/**
 * 
 * @author yuyang 主要做数据回显
 * 
 */
public class DisplayData {

	BaseDao baseDao = new BaseDaoImpl();
	private static DisplayData displayData = new DisplayData();

	public static DisplayData getInstance() {
		return displayData;
	}
	

	/*
	 * 根据网站站点ID，得到网站站点内容 
	 * return：WebSiteDto，数据存入WebSiteDto并返回
	 */
	public SiteUrl DisplayForWebSiteId(String siteid) {
		
		WebSiteDAOSQL webSiteDao = new WebSiteDAOSQL();
		
		return webSiteDao.getWebSite(siteid);
		
	}
	/*
	 * 根据任务url id得到该任务url
	 */
	public TaskUrlDto DisplayTaskUrlForUrlId(String id) {
		
		Connection conn = null;
		Statement stat = null;
		ResultSet result =null;
		
		TaskUrlDto taskurldto = new TaskUrlDto();

		String selectsql = "select task_url from task_urls where id='" + id
				+ "'";

		//ResultSet resultSet = baseDao.select(selectsql);

		try {
			conn = DBUtils.getConnection();
			stat = conn.createStatement();
			result = stat.executeQuery(selectsql);
			if (result.next()) {
				 
				taskurldto.setTask_url(result.getString("task_url"));
				
			}
		} catch (SQLException s) {
			s.printStackTrace();
		}finally{
			DBUtils.close(result);
			DBUtils.close(stat);
			DBUtils.close(conn); 
		}

		return taskurldto;

	}

}
